home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / UUCP / UUCon / Source / EnhancedText.m < prev    next >
Text File  |  1992-08-20  |  2KB  |  90 lines

  1. /*
  2.  
  3.   Ronin Consulting, Inc.
  4.     Copyright (C) 1992, Nicholas Christopher (nwc@gun.com)
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public
  17.     License along with this library; if not, write to the Free
  18.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. */
  21. #import "EnhancedText.h"
  22. #import <appkit/nextstd.h>
  23. #import <string.h>
  24.  
  25. static char *returnBuffer = (char *)0;
  26.  
  27. @implementation Text (EnhancedText)
  28.  
  29. - appendString: (const char *) str
  30. {
  31.    int len;
  32.  
  33.    len = [self textLength];
  34.    [self setSel: len : len];
  35.    [self replaceSel: str];
  36.    [self scrollSelToVisible];
  37.    
  38.    return self;
  39. }
  40.  
  41. - empty: sender
  42. {
  43.    int x;
  44.    BOOL editable, selectable;
  45.  
  46.    x = [self textLength] + 1;
  47.    [self setSel: 0 : x + 1];             /* select the entire text */
  48.  
  49.    /*
  50.     * To delete the text must be editable so copy aside the current
  51.     * editable and selectable settings, set the text editable, delete
  52.     * and then restore the copied aside values.
  53.     */
  54.    editable = [self isEditable];
  55.    selectable = [self isSelectable];
  56.  
  57.    [self setEditable: YES];
  58.    [self delete: sender];
  59.  
  60.    [self setEditable: editable];
  61.    [self setSelectable: selectable];
  62.  
  63.    return self;
  64. }
  65.  
  66. - (const char *) selectedText
  67. {
  68.    NXSelPt start, end;
  69.    int numChars;
  70.  
  71.    [self getSel: &start : &end];
  72.    numChars = end.cp - start.cp;
  73.  
  74.    if(returnBuffer)
  75.    {
  76.       NX_FREE(returnBuffer);
  77.       returnBuffer = (char *)0;
  78.    }
  79.    
  80.    NX_MALLOC(returnBuffer, char, numChars + 1);
  81.  
  82.    [self getSubstring: returnBuffer start: start.cp length: numChars];
  83.    returnBuffer[numChars] = (char)0;
  84.    
  85.    return (const char *)returnBuffer;
  86. }
  87.  
  88.  
  89. @end
  90.